package common.config.datasource.sharding.table;

import common.config.datasource.DataSourceConstants;
import common.config.datasource.sharding.config.ShardingSphereAlgorithmConstants;
import common.config.datasource.sharding.config.ShardingSphereAlgorithmUtil;
import org.springframework.stereotype.Component;

/**
 * sys_log表分片配置
 *
 * @author 米泽鹏
 * @since 2023-8-14 上午 11:47
 */
@Component("sysLogShardingConfig")
public class SysLogShardingConfig {

	/**
	 * 逻辑表名称
	 */
	public static final String LOGIC_TABLE_NAME = "sys_log";

	/**
	 * 真实数据节点
	 */
	public static final String ACTUAL_DATA_NODES = DataSourceConstants.SHARDING_DATASOURCE + ".sys_log_$->{1..2}";

	/**
	 * 算法名称
	 */
	public static final String SYS_LOG_TABLE_ALG = "sys_log_table_alg";
	public static final String SYS_LOG_TABLE_ALG_2 = "sys_log_table_alg_2";
	public static final String SYS_LOG_TABLE_ALG_3 = "sys_log_table_alg_3";

	static {
		ShardingSphereAlgorithmConstants.SHARDING_ALGORITHMS.put(SYS_LOG_TABLE_ALG, ShardingSphereAlgorithmUtil.buildInlineAlgorithmConfiguration("sys_log_$->{id % 2 + 1}"));
		ShardingSphereAlgorithmConstants.SHARDING_ALGORITHMS.put(SYS_LOG_TABLE_ALG_2, ShardingSphereAlgorithmUtil.buildHashModAlgorithmConfiguration("2"));
		ShardingSphereAlgorithmConstants.SHARDING_ALGORITHMS.put(SYS_LOG_TABLE_ALG_3, ShardingSphereAlgorithmUtil.buildInlineAlgorithmConfiguration("sys_log_$->{execution_time > 1000 ? 2 : 1}"));
	}

}
